package com.util;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class DRabbitConfig {
    @Bean(name = "normal1")
    public Queue normal1() {
        HashMap<String, Object> params = new HashMap<>();
        params.put("x-dead-letter-exchange", "deadExchange");
        params.put("x-dead-letter-routing-key", "deadRouting");
        params.put("x-message-ttl", 10000);
        return new Queue("normal", false, false, false, params);
    }

    @Bean(name = "dead1")
    public Queue dead1() {
        return new Queue("dead", false, false, false, null);
    }

    @Bean(name = "deadExchange1")
    public DirectExchange deadExchange1() {
        return new DirectExchange("deadExchange", false, false, null);
    }
    @Bean(name = "normalExchange1")
    public DirectExchange normalExchange1() {
        return new DirectExchange("normalExchange", false, false, null);
    }

    @Bean
    public Binding binding11(@Qualifier("normal1") Queue queue, @Qualifier("normalExchange1") DirectExchange directExchange) {
        return BindingBuilder.bind(queue).to(directExchange).with("normalRouting");
    }
    @Bean
    public Binding binding21(@Qualifier("dead1") Queue queue,  @Qualifier("deadExchange1") DirectExchange directExchange) {
        return BindingBuilder.bind(queue).to(directExchange).with("deadRouting");
    }
}
